package lanQiaoBei.violent_recursion;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/*
* 暴力递归(尝试)找出字符串的所有子串
* */
public class StrSubsequence {
    public static void main(String[] args) {
         realize("abc");
    }
    public static void realize(String str){
        char[] chars = str.toCharArray();
        fun(chars,0,new ArrayList<Character>());
    }

    private static void fun(char[] chars, int i, List<Character> characters) {
        if (i == chars.length) {
            System.out.println(characters);
            return;
        }
        List<Character> copyList = copyList(characters);
        characters.add(chars[i]);
        fun(chars, i + 1, copyList);
        List<Character> copyList1 = copyList(characters);
        fun(chars, i + 1, copyList1);
    }

    private static List<Character> copyList(List<Character> characters) {
        List<Character> copyList = new ArrayList<>(characters.size());
        for (Character character : characters) {
            copyList.add(character);
        }
        characters=null;
        return copyList;
    }
}
